from PySide2.QtWebEngineWidgets import QWebEngineView


class WebEngineView(QWebEngineView):
    def createWindow(self,QWebEnginePage_WebWindowType):
        page = WebEngineView(self)
        page.urlChanged.connect(self.on_url_changed)
        return page
    def on_url_changed(self,url):
        if "call" in url.url():
            #     导入模块
            # call/className/funName
            data = url.url().split("=")
            # 获取类名
            obj_class_name = self.import_fun(data[1])
            # 实例化对象
            obj = obj_class_name()
            # 调用print_name方法
            getattr(obj, data[2])()

        else:
            self.setUrl(url)

    # 模块引用
    def import_fun(self,fun_str):
        model_list = fun_str.split(".")
        model = None
        for index,item in enumerate(model_list):
            if index == 0:
                model = __import__(item)
            else:
                model = getattr(model,item)
        return model;